﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommunityToolkitMvvmDemo.ViewModels
{
    public partial class StudentVM : ObservableRecipient, IRecipient<PropertyChangedMessage<string>>, IRecipient<PropertyChangedMessage<int>>
    {
        [ObservableProperty]
        private string information = "INSERT INTO Students ...";

        /// <summary>
        /// 接收来自 <see cref="StudentFormViewModel"/> 的属性变化的消息，并更新 <see cref="Information"/>
        /// </summary>
        public void Receive(PropertyChangedMessage<string> message) // 接收广播消息
        {
            if (message.Sender is StudentFormViewModel vm)
                Information = vm.SqlQuery;
        }
        public void Receive(PropertyChangedMessage<int> message) // 接收广播消息
        {
            if (message.Sender is StudentFormViewModel vm)
                Information = vm.SqlQuery;
        }
    }

}
